<?php

/**
 * Form for adding and editing worktime data
 */

class Application_Form_Worktime extends Zend_Form
{
    // Mapping keys to db columns
    protected static $DB_MAPPING = array(
		"description" => "description",
		"request" => "request",
		"request_additional" => "request_additional",
		"date_from" => "date_from",
		"date_to" => "date_to",
		"serie_from" => "serie_from",
		"serie_to" => "serie_to",
		"once_serie" => "once_serie",
        "expire_date" => "expire_date"
    );
    
    // Mapping Max Length from db
    protected static $MAX_LENGTH = array (
		"description" => "2500",
		"request" => "2500",
		"request_additional" => "2500",
		"event_type" => "10"
    );

    public function init()
    {
	    // Validators
	    $valid_date = new Zend_Validate_Date(array('format' => 'dd.MM.yyyy'));
	    $valid_datetime = new Zend_Validate_Date(array('format' => 'dd.MM.yyyy HH:mm'));
	    $valid_notempty = new Zend_Validate_NotEmpty();

        /*$model = new Model_Worktime();

        $r = $model->listWorkers();
        $b = array();
	    foreach($r as $sub_array) 
	    {
           $b[$sub_array['id']]=$sub_array['forename']." ".$sub_array['surname'];
		
	    }*/              

	    // Set action POST as default
	    $this->setMethod('post');
	
	    // Elements
	    // Dynamic select for workers
	
	    $this->addElement('select', "Mitarbeiter", array(
	        'label' => 'Mitarbeiter:* ',
	        'required' => true,
	        'MultiOptions' => array(/*"0"=>"Mitarbeiter auswählen"*/),
	        'validators' => array()
	    ));

	    /*$this->addElement('select', "eventType", array(
	        'label' => 'Typ',
	        'required' => true,
	        'MultiOptions' => (array("Einzeleintrag","Serie")),
	        'validators' => array()
	    ));
	
	    $this->addElement('text', $this::$DB_MAPPING['serie_from'], array(
	        'label' => 'Serie von: (Tag.Monat.Jahr)',
	        'required' => false,
	        'filters' => array('StringTrim'),
	        'validators' => array($valid_notempty, $valid_date)
	        ));
	
	    $this->addElement('text', $this::$DB_MAPPING['serie_to'], array(
	        'label' => 'Serie bis: (Tag.Monat.Jahr)',
	        'required' => false,
	        'filters' => array('StringTrim'),
	        'validators' => array($valid_notempty, $valid_date)
	    ));*/

	    $this->addElement('text', $this::$DB_MAPPING['date_from'], array(
	        'label' => 'Startdatum:* ',
	        'required' => true,
	        'filters' => array('StringTrim'),
	        'validators' => array($valid_notempty, $valid_datetime)
	    ));
	
	    $this->addElement('text', $this::$DB_MAPPING['date_to'], array(
	        'label' => 'Enddatum:* ',
	        'required' => true,
	        'filters' => array('StringTrim'),
	        'validators' => array($valid_notempty, $valid_datetime)
	    ));
        
	    $this->addElement('textarea', $this::$DB_MAPPING['description'], array(
	        'label' => 'Beschreibung: ',
	        'required' => false,
	        'filters' => array('StringTrim'),
	        'validators' => array(
		    $valid_notempty, 
		    array("StringLength",false,
		    array('max' => $this::$MAX_LENGTH['description'])),
	    )));        
        
        /*$this->addElement('radio', 'once_serie', array(
            'label'=>'Frequenz:',
            'multiOptions'=>array(
                'e' => 'Einmaliger Termin',
                's' => 'Wöchentlicher Termin',
                'x' => 'Alle X Tage'                
             ),
        ));*/
        
	    $this->addElement('select', $this::$DB_MAPPING['once_serie'], array(
	        'label' => 'Frequenz:* ',
	        'required' => true,
	        'MultiOptions' => array('e' => 'Einmaliger Termin',
                                    's' => 'Wöchentlicher Termin',
                                    'x' => 'Alle X Tage'),
	        'validators' => array()
	    ));
        
	    $this->addElement('text', "x_days", array(
	        'label' => 'Tagesschritte:* ',
	        'required' => true,
	        'filters' => array('StringTrim'),
	        'validators' => array($valid_notempty)
	    ));        
        
	    $this->addElement('text', $this::$DB_MAPPING['expire_date'], array(
	        'label' => 'Letztmalig am:* ',
	        'required' => true,
	        'filters' => array('StringTrim'),
	        'validators' => array($valid_notempty, $valid_date)
	    ));        

	    $this->addElement('submit', 'submit', array(
	        'ignore' => true,
	        'label' => 'Speichern'
	    ));
        
	    $this->addElement('hidden', "modus", array(
	        'required' => true
	    ));        
        
	
    }
}
